package com.example.springbootmybatis.service;

import com.example.springbootmybatis.entity.Product;
import com.example.springbootmybatis.mapper.ProductMapper;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @title: ProductService
 * @Author Tan
 * @Date: 2021/6/24 22:18
 * @Version 1.0
 */
@Service
public class ProductService {
    @Resource
    private ProductMapper productMapper;

    public List<Product> Search() {
        List<Product> productList = productMapper.selectByExample(null);
        return productList;
    }

    public List<Product> selectHomePageDataList() {
        List<Product> productList = productMapper.selectHomePageDataList();
        return productList;
    }

    public int updateProduct(List<Product> productList) {
        int count = 0;
        for (Product product : productList) {
            int result = productMapper.updateByPrimaryKey(product);
            count = result + count;
        }
        return count;
    }
}
